<?php
    require_once("storage/xmlparser.php");

    /**
     * Klasse for et sted.
     */
    class PlaceModel {

        private $name;
        private $nnUrl;
        private $nbUrl;
        private $enUrl;

        private $forecastDays; //array
        private $forecast;
        private $period1, $period2, $period3;

        public function __construct($name, $nbUrl){
            $this->name = utf8_decode($name);
            $this->nbUrl = $nbUrl;
            $this->nnUrl = PlaceModel::toNNURL($nbUrl);
            $this->enUrl = PlaceModel::toENURL($nbUrl);
        }

        public function getName(){ return utf8_encode($this->name); }
        public function getNbUrl(){ return $this->nbUrl; }
        public function getNnUrl(){ return $this->bbUrl; }
        public function getEnUrl(){ return $this->enUrl; }
		public function getPeriod1() {return $this->period1; }
		public function getPeriod2() {return $this->period2; }
		public function getPeriod3() {return $this->period3; }
		
        public function getForecast($daysAhead){
            return $this->forecast;
        }
        
        public function setForecast() {
//            $uri = 'http://www.yr.no/sted/Norge/Telemark/Sauherad/Gvarv/varsel.xml';
            $obj = new xmlParser();
            $this->forecast = $obj->getWeather($this->nbUrl);
        }
        
        public function setCurrentForecast($date) {
            $this->period1 = $this->forecast[$date . '-1'];
            $this->period2 = $this->forecast[$date . '-2'];
            $this->period3 = $this->forecast[$date . '-3'];
        }
        
        public function setName($param){ $this->name = $param; }
        
        public function toNNURL($url) {
            $tempurl = explode("/",$url);
            //echo "<pre>"; <- for testing purposes
            //print_r($tempurl);
            //echo " </pre>";
            
            $tempurl[3] = "stad";
            $tempurl[4] = "Noreg";
            return implode($tempurl, "/");
        }
        
        public function toENURL($url) {
            $tempurl = explode("/",$url);
            //echo "<pre>"; <- for testing purposes
            //print_r($tempurl);
            //echo " </pre>";
            
            $tempurl[3] = "place";
            $tempurl[4] = "Norway";
            $tempurl[8] = "forecast.xml";
            return implode($tempurl, "/");
        }   
    }
?>